<?php
//自动生成,请根据需要修改
namespace app\article\controller;
use app\common\controller\Base;
use think\facade\Request;
use think\Db;
/**
* @title 文章评论表接口
* @description 文章评论表说明
* @group 文章
*/
class Comment extends Base{

	/**
	* @title 插入记录
	* @description 插入文章评论表数据
	* @author 开发者（zzz）
	* @url /article/comment/add
	* @method post
	*
	* @param name:token require:1 default: desc:token
	*
	* @param name:article_id type:VarChar require:1 default:0 other: desc:文章id
	* @param name:comment type:VarChar require:1 default:0 other: desc:评论内容
	* @param name:picks_count type:Int require:1 default:0 other: desc:点赞量
	* @param name:create_time type:Date require:1 default:0 other: desc:创建时间
	* @param name:update_time type:Date require:1 default:0 other: desc:更新时间
	* @param name:updater type:VarChar require:1 default:0 other: desc:更新者
	* @param name:status type:TinyInt require:1 default:0 other: desc:当前数据状态
	* @param name:ext1 type:VarChar require:1 default:0 other: desc:预备字段1
	* @param name:creater type:VarChar require:1 default:0 other: desc:创建者
	*
	*
	* @return article_id:文章id
	* @return comment:评论内容
	* @return picks_count:点赞量
	* @return create_time:创建时间
	* @return update_time:更新时间
	* @return updater:更新者
	* @return status:当前数据状态
	* @return ext1:预备字段1
	* @return creater:创建者
	*
	*/
	public function add ()
    {
        $input = input();
        //模块 - 输入数据
        $input['article_id'] = Request::post('article_id');
        $input['comment'] = Request::post('comment');
        $input['picks_count'] = '0';
        $input['create_time'] = date("Y-m-d H:i:s");
        $input['update_time'] = date("Y-m-d H:i:s");
        $input['updater'] = Request::post('updater');
        $input['status'] = 1;
        $input['ext1'] = Request::post('ext1');
        $input['creater'] = Request::post('creater');

        // input结果返回
        $msg['data']['article_id'] = $input['article_id'];
        $msg['data']['comment'] = $input['comment'];
        $msg['data']['picks_count'] = $input['picks_count'];
        $msg['data']['create_time'] = $input['create_time'];
        $msg['data']['update_time'] = $input['update_time'];
        $msg['data']['updater'] = $input['updater'];
        $msg['data']['status'] = $input['status'];
        $msg['data']['ext1'] = $input['ext1'];
        $msg['data']['creater'] = $input['creater'];

        $user = getIdByToken($input['token']);//通过token获取用户id
        if (count($user->all()) == 0) {
            $msg['msg'] = '无法获取用户信息';
            return $this->errorJson($msg);
        }
        $user_id = $user->all()['0']['account_id'];
        $input['updater'] = $user_id;
        $input['creater'] = $user_id;

		//模块 - 验证器
		$commentValidate = new \app\article\validate\Comment;
		$validate = $commentValidate->scene('add')->check($input);
		if (!$validate) {
			$msg['msg'] = '验证失败';
			$msg['validate'] = $commentValidate->getError();
			return $this->errorJson($msg);
		}


		// ---	模块 - 新增  ---
		//插入的数据
		$insert_data = [
			'article_id'=>$input['article_id'],
			'comment'=>$input['comment'],
			'picks_count'=>$input['picks_count'],
			'create_time'=>$input['create_time'],
			'update_time'=>$input['update_time'],
			'updater'=>$input['updater'],
			'status'=>$input['status'],
			'ext1'=>$input['ext1'],
			'creater'=>$input['creater'],
		];
		//添加数据
		$insert_res = Db::name('comment')->data($insert_data)->insert();
		if(!$insert_res){
			$msg['msg'] = '插入数据失败！';
			return $this->errorJson($msg);
		}
		$msg['res'] = $insert_res;


		//接口输出json数据
		$msg['msg'] = '操作成功！';
		return $this->successJson($msg);
	}
	/**
	* @title 获取列表数据（paginate）
	* @description 获取文章评论表的列表数据（分页）
	* @author 开发者（zzz）
	* @url /article/comment/get_list
	* @method *
	*
	* @param name:token require:1 default: desc:token
	*
	* @param name:id type:Int require:1 default:0 other: desc:id
	* @param name:article_id type:VarChar require:1 default:0 other: desc:文章id
	* @param name:comment type:VarChar require:1 default:0 other: desc:评论内容
	* @param name:picks_count type:Int require:1 default:0 other: desc:点赞量
	* @param name:create_time type:Date require:1 default:0 other: desc:创建时间
	* @param name:update_time type:Date require:1 default:0 other: desc:更新时间
	* @param name:updater type:VarChar require:1 default:0 other: desc:更新者
	* @param name:status type:TinyInt require:1 default:0 other: desc:当前数据状态
	* @param name:ext1 type:VarChar require:1 default:0 other: desc:预备字段1
	* @param name:creater type:VarChar require:1 default:0 other: desc:创建者
	*
	* @param name:page type:Int require:0 default:0 other: desc:当前页
	* @param name:pagesize type:Int require:0 default:0 other: desc:每页数量
	*
	* @return id:id
	* @return article_id:文章id
	* @return comment:评论内容
	* @return picks_count:点赞量
	* @return create_time:创建时间
	* @return update_time:更新时间
	* @return updater:更新者
	* @return status:当前数据状态
	* @return ext1:预备字段1
	* @return creater:创建者
	*
	*/
	public function get_list (){
		$input=input();
		//模块 - 输入数据
		$input['id'] = Request::param('id/d');
		$input['article_id'] = Request::param('article_id');
		$input['comment'] = Request::param('comment');
		$input['picks_count'] = Request::param('picks_count/d');
		$input['create_time'] = Request::param('create_time');
		$input['update_time'] = Request::param('update_time');
		$input['updater'] = Request::param('updater');
		$input['status'] = Request::param('status');
		$input['ext1'] = Request::param('ext1');
		$input['creater'] = Request::param('creater');

		// input结果返回
		$msg['data']['id'] = $input['id'];
		$msg['data']['article_id'] = $input['article_id'];
		$msg['data']['comment'] = $input['comment'];
		$msg['data']['picks_count'] = $input['picks_count'];
		$msg['data']['create_time'] = $input['create_time'];
		$msg['data']['update_time'] = $input['update_time'];
		$msg['data']['updater'] = $input['updater'];
		$msg['data']['status'] = $input['status'];
		$msg['data']['ext1'] = $input['ext1'];
		$msg['data']['creater'] = $input['creater'];

		// ---	模块 - 查询  ---
		//查询条件
		$temp_map = [
			['id','=',$input['id']],
			['article_id','like','%'.$input['article_id'].'%'],
			['comment','like','%'.$input['comment'].'%'],
			['picks_count','=',$input['picks_count']],
			['create_time','=',$input['create_time']],
			['update_time','=',$input['update_time']],
			['updater','like','%'.$input['updater'].'%'],
			['status','=',$input['status']],
			['ext1','like','%'.$input['ext1'].'%'],
			['creater','like','%'.$input['creater'].'%'],
		];
		//去除为空的条件
		$paginate_map = [];
		foreach ($temp_map as $k=>$v){
			if ($v[2]===null || $v[2]=='' || $v[2]=='%%'){
				continue;
			}
			array_push($paginate_map,$v);
		}

		//获取数据
		$select_res = Db::name('comment a')
            ->field('a.*,b.title')
            ->leftjoin('article b','a.article_id=b.id')
            ->where($paginate_map)
            ->paginate();

		// paginate 返回数据
		$msg['list'] = $select_res;


		//接口输出json数据
		$msg['msg'] = '操作成功！';
		return $this->successJson($msg);
	}
	/**
	* @title 获取列表数据（select）
	* @description 获取文章评论表的列表数据（无分页）
	* @author 开发者（zzz）
	* @url /article/comment/get_select
	* @method *
	*
	* @param name:token require:1 default: desc:token
	*
	* @param name:id type:Int require:1 default:0 other: desc:id
	* @param name:article_id type:VarChar require:1 default:0 other: desc:文章id
	* @param name:comment type:VarChar require:1 default:0 other: desc:评论内容
	* @param name:picks_count type:Int require:1 default:0 other: desc:点赞量
	* @param name:create_time type:Date require:1 default:0 other: desc:创建时间
	* @param name:update_time type:Date require:1 default:0 other: desc:更新时间
	* @param name:updater type:VarChar require:1 default:0 other: desc:更新者
	* @param name:status type:TinyInt require:1 default:0 other: desc:当前数据状态
	* @param name:ext1 type:VarChar require:1 default:0 other: desc:预备字段1
	* @param name:creater type:VarChar require:1 default:0 other: desc:创建者
	*
	*
	* @return id:id
	* @return article_id:文章id
	* @return comment:评论内容
	* @return picks_count:点赞量
	* @return create_time:创建时间
	* @return update_time:更新时间
	* @return updater:更新者
	* @return status:当前数据状态
	* @return ext1:预备字段1
	* @return creater:创建者
	*
	*/
	public function get_select (){
		$input=input();
		//模块 - 输入数据
		$input['id'] = Request::param('id/d');
		$input['article_id'] = Request::param('article_id');
		$input['comment'] = Request::param('comment');
		$input['picks_count'] = Request::param('picks_count/d');
		$input['create_time'] = Request::param('create_time');
		$input['update_time'] = Request::param('update_time');
		$input['updater'] = Request::param('updater');
		$input['status'] = Request::param('status');
		$input['ext1'] = Request::param('ext1');
		$input['creater'] = Request::param('creater');

		// input结果返回
		$msg['data']['id'] = $input['id'];
		$msg['data']['article_id'] = $input['article_id'];
		$msg['data']['comment'] = $input['comment'];
		$msg['data']['picks_count'] = $input['picks_count'];
		$msg['data']['create_time'] = $input['create_time'];
		$msg['data']['update_time'] = $input['update_time'];
		$msg['data']['updater'] = $input['updater'];
		$msg['data']['status'] = $input['status'];
		$msg['data']['ext1'] = $input['ext1'];
		$msg['data']['creater'] = $input['creater'];

		// ---	模块 - 查询  ---
		//查询条件
		$temp_map = [
			['id','=',$input['id']],
			['article_id','like','%'.$input['article_id'].'%'],
			['comment','like','%'.$input['comment'].'%'],
			['picks_count','=',$input['picks_count']],
			['create_time','=',$input['create_time']],
			['update_time','=',$input['update_time']],
			['updater','like','%'.$input['updater'].'%'],
			['status','=',$input['status']],
			['ext1','like','%'.$input['ext1'].'%'],
			['creater','like','%'.$input['creater'].'%'],
		];
		//去除为空的条件
		$select_map = [];
		foreach ($temp_map as $k=>$v){
			if ($v[2]===null || $v[2]=='' || $v[2]=='%%'){
				continue;
			}
			array_push($select_map,$v);
		}

		//获取数据
		$select_res = Db::name('comment')->where($select_map)->select();

		// select 返回数据
		$msg['list'] = $select_res;


		//接口输出json数据
		$msg['msg'] = '操作成功！';
		return $this->successJson($msg);
	}
	/**
	* @title 获取单条数据
	* @description 根据ID获取文章评论表的指定记录
	* @author 开发者（zzz）
	* @url /article/comment/info
	* @method *
	*
	* @param name:token require:1 default: desc:token
	*
	* @param name:id type:Int require:1 default:0 other: desc:id
	*
	*
	* @return id:id
	*
	*/
	public function info (){
		$input=input();
		//模块 - 输入数据
		$input['id'] = Request::param('id/d');

		// input结果返回
		$msg['data']['id'] = $input['id'];

		//模块 - 验证器
		$commentValidate = new \app\article\validate\Comment;
		$validate = $commentValidate->scene('only_id')->check($input);
		if (!$validate) {
			$msg['msg'] = '验证失败';
			$msg['validate'] = $commentValidate->getError();
			return $this->errorJson($msg);
		}

		// ---	模块 - 查询  ---
		//查询条件
		$temp_map = [
			['id','=',$input['id']],
		];
		//去除为空的条件
		$find_map = [];
		foreach ($temp_map as $k=>$v){
			if ($v[2]===null || $v[2]=='' || $v[2]=='%%'){
				continue;
			}
			array_push($find_map,$v);
		}

		//获取数据
		$select_res = Db::name('comment')->where($find_map)->find();

		// find 返回数据
		$msg['data'] = $select_res;


		//接口输出json数据
		$msg['msg'] = '操作成功！';
		return $this->successJson($msg);
	}
	/**
	* @title 更新记录
	* @description 根据ID更新文章评论表指定记录的数据
	* @author 开发者（zzz）
	* @url /article/comment/edit
	* @method post
	*
	* @param name:token require:1 default: desc:token
	*
	* @param name:id type:Int require:1 default:0 other: desc:id
	* @param name:article_id type:VarChar require:1 default:0 other: desc:文章id
	* @param name:comment type:VarChar require:1 default:0 other: desc:评论内容
	* @param name:picks_count type:Int require:1 default:0 other: desc:点赞量
	* @param name:create_time type:Date require:1 default:0 other: desc:创建时间
	* @param name:update_time type:Date require:1 default:0 other: desc:更新时间
	* @param name:updater type:VarChar require:1 default:0 other: desc:更新者
	* @param name:status type:TinyInt require:1 default:0 other: desc:当前数据状态
	* @param name:ext1 type:VarChar require:1 default:0 other: desc:预备字段1
	* @param name:creater type:VarChar require:1 default:0 other: desc:创建者
	*
	*
	* @return id:id
	* @return article_id:文章id
	* @return comment:评论内容
	* @return picks_count:点赞量
	* @return create_time:创建时间
	* @return update_time:更新时间
	* @return updater:更新者
	* @return status:当前数据状态
	* @return ext1:预备字段1
	* @return creater:创建者
	*
	*/
	public function edit (){
		$input=input();
		//模块 - 输入数据
		$input['id'] = Request::post('id/d');
		$input['article_id'] = Request::post('article_id');
		$input['comment'] = Request::post('comment');
		$input['picks_count'] = Request::post('picks_count/d');
		$input['create_time'] = Request::post('create_time');
		$input['update_time'] = Request::post('update_time');
		$input['updater'] = Request::post('updater');
		$input['status'] = Request::post('status');
		$input['ext1'] = Request::post('ext1');
		$input['creater'] = Request::post('creater');

		// input结果返回
		$msg['data']['id'] = $input['id'];
		$msg['data']['article_id'] = $input['article_id'];
		$msg['data']['comment'] = $input['comment'];
		$msg['data']['picks_count'] = $input['picks_count'];
		$msg['data']['create_time'] = $input['create_time'];
		$msg['data']['update_time'] = $input['update_time'];
		$msg['data']['updater'] = $input['updater'];
		$msg['data']['status'] = $input['status'];
		$msg['data']['ext1'] = $input['ext1'];
		$msg['data']['creater'] = $input['creater'];

		//模块 - 验证器
		$commentValidate = new \app\article\validate\Comment;
		$validate = $commentValidate->scene('all_field')->check($input);
		if (!$validate) {
			$msg['msg'] = '验证失败';
			$msg['validate'] = $commentValidate->getError();
			return $this->errorJson($msg);
		}

		// ---	模块 - 修改  ---
		//更新的条件
		$update_date = [
		'id'=>$input['id'],
		];
		//更新的数据
		$update_map = [
			'article_id'=>$input['article_id'],
			'comment'=>$input['comment'],
			'picks_count'=>$input['picks_count'],
			'create_time'=>$input['create_time'],
			'update_time'=>$input['update_time'],
			'updater'=>$input['updater'],
			'status'=>$input['status'],
			'ext1'=>$input['ext1'],
			'creater'=>$input['creater'],
		];
		//获取数据
		$update_res = Db::name('comment')->where($update_date)->update($update_map);
		if(!$update_res){
			$msg['msg'] = '更新据失败！';
			return $this->errorJson($msg);
		}
		$msg['res'] = $update_res;


		//接口输出json数据
		$msg['msg'] = '操作成功！';
		return $this->successJson($msg);
	}
	/**
	* @title 按条件删除记录
	* @description 按条件删除文章评论表的数据
	* @author 开发者（zzz）
	* @url /article/comment/delete
	* @method post
	*
	* @param name:token require:1 default: desc:token
	*
	* @param name:id type:Int require:1 default:0 other: desc:id
	* @param name:article_id type:VarChar require:1 default:0 other: desc:文章id
	* @param name:comment type:VarChar require:1 default:0 other: desc:评论内容
	* @param name:picks_count type:Int require:1 default:0 other: desc:点赞量
	* @param name:create_time type:Date require:1 default:0 other: desc:创建时间
	* @param name:update_time type:Date require:1 default:0 other: desc:更新时间
	* @param name:updater type:VarChar require:1 default:0 other: desc:更新者
	* @param name:status type:TinyInt require:1 default:0 other: desc:当前数据状态
	* @param name:ext1 type:VarChar require:1 default:0 other: desc:预备字段1
	* @param name:creater type:VarChar require:1 default:0 other: desc:创建者
	*
	*
	* @return id:id
	* @return article_id:文章id
	* @return comment:评论内容
	* @return picks_count:点赞量
	* @return create_time:创建时间
	* @return update_time:更新时间
	* @return updater:更新者
	* @return status:当前数据状态
	* @return ext1:预备字段1
	* @return creater:创建者
	*
	*/
	public function delete (){
		$input=input();
		//模块 - 输入数据
		$input['id'] = Request::post('id/d');
		$input['article_id'] = Request::post('article_id');
		$input['comment'] = Request::post('comment');
		$input['picks_count'] = Request::post('picks_count/d');
		$input['create_time'] = Request::post('create_time');
		$input['update_time'] = Request::post('update_time');
		$input['updater'] = Request::post('updater');
		$input['status'] = Request::post('status');
		$input['ext1'] = Request::post('ext1');
		$input['creater'] = Request::post('creater');

		// input结果返回
		$msg['data']['id'] = $input['id'];
		$msg['data']['article_id'] = $input['article_id'];
		$msg['data']['comment'] = $input['comment'];
		$msg['data']['picks_count'] = $input['picks_count'];
		$msg['data']['create_time'] = $input['create_time'];
		$msg['data']['update_time'] = $input['update_time'];
		$msg['data']['updater'] = $input['updater'];
		$msg['data']['status'] = $input['status'];
		$msg['data']['ext1'] = $input['ext1'];
		$msg['data']['creater'] = $input['creater'];

		// ---  模块 - 删除  ---
		//删除的条件
		$temp_map = [
			['id','=',$input['id']],
			['article_id','=',$input['article_id']],
			['comment','=',$input['comment']],
			['picks_count','=',$input['picks_count']],
			['create_time','=',$input['create_time']],
			['update_time','=',$input['update_time']],
			['updater','=',$input['updater']],
			['status','=',$input['status']],
			['ext1','=',$input['ext1']],
			['creater','=',$input['creater']],
		];
		$delete_map = [];
		foreach ($temp_map as $k=>$v){
			if ($v[2] == null || $v[2] == ''){
				continue;
			}
			array_push($delete_map,$v);
		}
		if(empty($delete_map)){
			$msg['msg'] = '删除条件不能为空';
			return $this->errorJson($msg);
		}

		//删除数据
		$delete_res = Db::name('comment')->where($delete_map)->delete();
		if(!$delete_res){
			$msg['msg'] = '删除数据失败！';
			return $this->errorJson($msg);
		}
		$msg['res'] = $delete_res;


		//接口输出json数据
		$msg['msg'] = '操作成功！';
		return $this->successJson($msg);
	}

    /**
     * @title 获取列表数据（paginate）
     * @description 获取文章评论表的列表数据通过文章id（分页）
     * @author 开发者（zzz）
     * @url /article/comment/get_list_by_article_id
     * @method *
     *
     * @param name:token require:1 default: desc:token
     *
     * @param name:id type:Int require:1 default:0 other: desc:id
     * @param name:article_id type:VarChar require:1 default:0 other: desc:文章id
     * @param name:comment type:VarChar require:1 default:0 other: desc:评论内容
     * @param name:picks_count type:Int require:1 default:0 other: desc:点赞量
     * @param name:create_time type:Date require:1 default:0 other: desc:创建时间
     * @param name:update_time type:Date require:1 default:0 other: desc:更新时间
     * @param name:updater type:VarChar require:1 default:0 other: desc:更新者
     * @param name:status type:TinyInt require:1 default:0 other: desc:当前数据状态
     * @param name:ext1 type:VarChar require:1 default:0 other: desc:预备字段1
     * @param name:creater type:VarChar require:1 default:0 other: desc:创建者
     *
     * @param name:page type:Int require:0 default:0 other: desc:当前页
     * @param name:pagesize type:Int require:0 default:0 other: desc:每页数量
     *
     * @return id:id
     * @return article_id:文章id
     * @return comment:评论内容
     * @return picks_count:点赞量
     * @return create_time:创建时间
     * @return update_time:更新时间
     * @return updater:更新者
     * @return status:当前数据状态
     * @return ext1:预备字段1
     * @return creater:创建者
     *
     */
    public function get_list_by_article_id (){
        $input=input();
        //模块 - 输入数据
        $input['id'] = Request::param('id/d');
        $input['article_id'] = Request::param('article_id');
        $input['comment'] = Request::param('comment');
        $input['picks_count'] = Request::param('picks_count/d');
        $input['create_time'] = Request::param('create_time');
        $input['update_time'] = Request::param('update_time');
        $input['updater'] = Request::param('updater');
        $input['status'] = Request::param('status');
        $input['ext1'] = Request::param('ext1');
        $input['creater'] = Request::param('creater');

        // input结果返回
        $msg['data']['id'] = $input['id'];
        $msg['data']['article_id'] = $input['article_id'];
        $msg['data']['comment'] = $input['comment'];
        $msg['data']['picks_count'] = $input['picks_count'];
        $msg['data']['create_time'] = $input['create_time'];
        $msg['data']['update_time'] = $input['update_time'];
        $msg['data']['updater'] = $input['updater'];
        $msg['data']['status'] = $input['status'];
        $msg['data']['ext1'] = $input['ext1'];
        $msg['data']['creater'] = $input['creater'];

        //模块 - 验证器
        $commentValidate = new \app\article\validate\Comment;
        $validate = $commentValidate->scene('only_article_id')->check($input);
        if (!$validate) {
            $msg['msg'] = '验证失败';
            $msg['validate'] = $commentValidate->getError();
            return $this->errorJson($msg);
        }

        // ---	模块 - 查询  ---
        //查询条件
        $temp_map = [
            ['id','=',$input['id']],
            ['article_id','like','%'.$input['article_id'].'%'],
            ['comment','like','%'.$input['comment'].'%'],
            ['picks_count','=',$input['picks_count']],
            ['create_time','=',$input['create_time']],
            ['update_time','=',$input['update_time']],
            ['updater','like','%'.$input['updater'].'%'],
            ['status','=',$input['status']],
            ['ext1','like','%'.$input['ext1'].'%'],
            ['creater','like','%'.$input['creater'].'%'],
        ];
        //去除为空的条件
        $paginate_map = [];
        foreach ($temp_map as $k=>$v){
            if ($v[2]===null || $v[2]=='' || $v[2]=='%%'){
                continue;
            }
            array_push($paginate_map,$v);
        }

        //获取数据
        $select_res = Db::name('comment')->where($paginate_map)->paginate();

        // paginate 返回数据
        $msg['list'] = $select_res;


        //接口输出json数据
        $msg['msg'] = '操作成功！';
        return $this->successJson($msg);
    }
}
